//  echarts.图形渲染
  
// 饼形图
 function pieChart(){
  let myCharts = echarts.init(document.querySelector('.pie'))

  let  option  = {
    title:{
      text:'籍贯 Hometown',
      textStyle:{
        color:'#72787e'
      }
    },
    tooltip:{
      formatter:'{a}<br>{b} <b>{c}</b>人   占比{d}%'
    },
    series: [
      {
        name: '各地人员分布',
        type: 'pie',
        radius: ['10%', '60%'],
        center: ['50%', '50%'],
        roseType: 'area',
        itemStyle: {
          borderRadius: 5
        },
        data: [
          { value: 40, name: '广东省' },
          { value: 38, name: '河南省' },
          { value: 32, name: '河北省' },
          { value: 30, name: '广西省' },
          { value: 28, name: '湖北省' },
          { value: 26, name: '湖南省' },
          { value: 22, name: '云南省' },
          { value: 18, name: '广西省' }
        ]
      }
    ]
  }
  
  myCharts.setOption(option)
 }
 pieChart()

 // 折现图
 function lineChart(){
   let myCharts = echarts.init(document.querySelector('.line'))

   let option = {
    tooltip: {
      trigger: 'axis',
      position: function (pt) {
        return [pt[0], '10%'];
      }
    },
    
    title: {
      text: '薪资 salary',
      textStyle:{
        color:"#6d767e"
      }
      
    },
  
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['张三','李四','王五','赵六','王七']
    },
    yAxis: {
      type: 'value',
      boundaryGap: [0, '50%']
    },
    dataZoom: [
      {
        type: 'slider',
        start: 0,
        end: 15
      }
  
    ],
    legend:{top:20},
    color:["#ee6666","#5470c6"],
    series: [
      {
        name: '期望薪资',
        type: 'line',
        symbol: 'none',
        smooth:true,
        data:[200,400,300,600,200]
      },
       {
        name: '实际薪资',
        type: 'line',
        symbol: 'none',
        smooth:true,
  
        data:[400,700,200,500,300]
      }
    ],
    
  }

   myCharts.setOption(option)
 }
 lineChart()


 // 柱形图
 function barChart(){
    let myCharts = echarts.init(document.querySelector('.barChart'))

    let option = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          crossStyle: {
            color: '#999'
          }
        }
      },
    
      legend: { },
      xAxis: [
        {
          type: 'category',
          data: ['1组', '2组', '3组', '4组', '5组', '6组', '7组', '8组'],
          axisPointer: {
            type: 'shadow'
          }
        }
      ],
      yAxis: [
        {
          type: 'value',
          min: 0,
          max: 100,
          interval: 10,
          axisLabel: {
            formatter: '{value}分'
          }
        },
        {
          type: 'value',
          min: 0,
          max: 10,
          interval: 1,
          axisLabel: {
            formatter: '{value}人'
          }
        }
      ],
      // 网格（整个图表区域设置）
      grid: {
        top: 30,
        bottom: 30,
        left: '7%',
        right: '7%'
      },
      series: [
        {
          name: '平均分',
          type: 'bar',
          barWidth:'15',// 设置柱形宽度
          tooltip: {
            valueFormatter: function (value) {
              return value + ' 分';
            }
          },
          data: [83, 57, 90, 78, 66, 76, 77, 87, ]
        },
        {
          name: '低于60分的人数',
          type: 'bar',
          barWidth:'15',// 设置柱形宽度
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' 人';
            }
          },
          data: [2, 1, 3, 4, 2, 5, 2, 2, ]
        },
         {
          name: '60分到80分之间',
          type: 'bar',
          barWidth:'15',// 设置柱形宽度
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' 人';
            }
          },
          data: [3, 2, 1, 5, 1, 2, 3, 4, ]
        },
         {
          name: '高于80分的人',
          type: 'bar',
          barWidth:'15',// 设置柱形宽度
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' 人';
            }
          },
          data:[2, 3, 4, 5, 2, 2, 4,3,]
        },
      ]
    }
    myCharts.setOption(option)
 }

 barChart()

 
 // 地图

 function setMap(){
  let myCharts = echarts.init(document.querySelector('.map'))
  
 
  // 位置 + 经纬度
  var chinaGeoCoordMap = {
    "顺义校区": [
        116.4551,
        40.2539
    ],
    "海拉尔区": [
        119.736279,
        49.212189
    ],
    "市中区": [
        116.997777,
        36.651474
    ],
};
  var chinaDatas = [
    [
        {
            "name": "海拉尔区",
            "value": 0
        }
    ],
    [
        {
            "name": "市中区",
            "value": 0
        }
    ],
];

  var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
      var dataItem = data[i];
      var fromCoord = chinaGeoCoordMap[dataItem[0].name];
      var toCoord = [116.4551, 40.2539]; // 目标点经纬度（北京顺义校区）
      if (fromCoord && toCoord) {
        res.push([{
          coord: fromCoord,
          value: dataItem[0].value
        }, {
          coord: toCoord,
        }]);
      }
    }
    return res;
  };
  var series = [];
  [['顺义校区', chinaDatas]].forEach(function (item, i) {
    series.push({
      type: 'lines',
      zlevel: 2,
      effect: {
        show: true,
        period: 4, //箭头指向速度，值越小速度越快
        trailLength: 0.02, //特效尾迹长度[0,1]值越大，尾迹越长重
        symbol: 'arrow', //箭头图标
        symbolSize: 5, //图标大小
      },
      lineStyle: {
        normal: {
          width: 1, //尾迹线条宽度
          opacity: 1, //尾迹线条透明度
          curveness: 0.2 //尾迹线条曲直度
        }
      },
      data: convertData(item[1])
    }, {
      type: 'effectScatter',
      coordinateSystem: 'geo',
      zlevel: 2,
      rippleEffect: { //涟漪特效
        period: 4, //动画时间，值越小速度越快
        brushType: 'stroke', //波纹绘制方式 stroke, fill
        scale: 4 //波纹圆环最大限制，值越大波纹越大
      },
      label: {
        normal: {
          show: true,
          position: 'right', //显示位置
          offset: [5, 0], //偏移设置
          formatter: function (params) {//圆环显示文字
            return params.data.name;
          },
          fontSize: 12
        },
        emphasis: {
          show: true
        }
      },
      symbol: 'circle',
      symbolSize: function (val) {
        return 4 + val[2] * 5; //圆环大小
      },
      itemStyle: {
        normal: {
          show: false,
          color: '#f00'
        }
      },
      data: item[1].map(function (dataItem) {
        return {
          name: dataItem[0].name,
          value: chinaGeoCoordMap[dataItem[0].name].concat([dataItem[0].value])
        };
      }),
    },
      //被攻击点
      {
        type: 'scatter',
        coordinateSystem: 'geo',
        zlevel: 2,
        rippleEffect: {
          period: 4,
          brushType: 'stroke',
          scale: 4
        },
        label: {
          normal: {
            show: true,
            position: 'right',
            offset: [5, 0],
            color: '#9eca7f', // 目标点文字颜色
            formatter: '{b}',
            textStyle: {
              color: "#9eca7f"
            }
          },
          emphasis: {
            show: true,
            color: "#f60", // 目标点鼠标移入的颜色
          }
        },
        symbol: 'pin',
        symbolSize: 50,
        data: [{
          name: item[0],
          value: chinaGeoCoordMap[item[0]].concat([10]),
        }],
      }
    );
  });

  let option = {
    title: {
      text: '来京路线 From',
      textStyle: {
        color: '#6d767e'
      }
    },
    // tooltip: {
    //   trigger: 'item',
    //   backgroundColor: 'rgba(166, 200, 76, 0.82)',
    //   borderColor: '#FFFFCC',
    //   showDelay: 0,
    //   hideDelay: 0,
    //   enterable: true,
    //   transitionDuration: 0,
    //   extraCssText: 'z-index:100',
    //   formatter: function (params, ticket, callback) {
    //     //根据业务自己拓展要显示的内容
    //     var res = "";
    //     var name = params.name;
    //     var value = params.value[params.seriesIndex + 1];
    //     res = "<span style='color:#fff;'>" + name + "</span><br/>数据：" + value;
    //     return res;
    //   }
    // },
    // backgroundColor: "#013954",
    // visualMap: { //图例值控制
    //   min: 0,
    //   max: 1,
    //   calculable: true,
    //   show: false,
    //   color: ['#f44336', '#fc9700', '#ffde00', '#ffde00', '#00eaff'],
    //   textStyle: {
    //     color: '#fff'
    //   }
    // },
    geo: {
      map: 'china',
      zoom: 1.2,
      label: {
        emphasis: {
          show: false
        }
      },
      roam: true, //是否允许缩放
      itemStyle: {
        normal: {
          // color: 'rgba(51, 69, 89, .5)', //地图背景色
          // color: '#5a6fc0', //地图背景色
          // borderColor: '#516a89', //省市边界线00fcff 516a89
          borderWidth: 1
        },
        emphasis: {
          color: 'rgba(37, 43, 61, .5)' //悬浮背景
        }
      }
    },
    series: series
  };

  


  myCharts.setOption(option)
}

setMap()


let total = document.querySelector('.total')
let avgSalary = document.querySelector('.avgSalary')
let avgAge = document.querySelector('.avgAge')
let proportion = document.querySelector('.proportion')



// 发送ajax进行渲染数据
axios({
  method:'get',
  url:'/student/overview'
}).then(({data:res})=>{
  total.innerHTML = res.data.total
  avgSalary.innerHTML = res.data.avgSalary
  avgAge.innerHTML = res.data.avgAge
  proportion.innerHTML = res.data.proportion
})



